﻿Imports FastReport.Report
Imports MySql.Data.MySqlClient
Public Class frmRptChekRefService
    Dim Strsql As String
    Dim _mysql As New ClsSQLhelper
    Public Report_Name As String
    Public Primary_Key As Integer
    Public CID_Criteria As String
    Private Sub frmRptChekRefService_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try

            'Strsql = "Select CID from m_person where CODE_ID like '%PE9202%'"
            'Dim DT_m_person_Dup As New DataTable
            'DT_m_person_Dup = _mysql.GetMYSQLDataTable(Strsql, "m_person")
            'If DT_m_person_Dup.Rows.Count = 0 Then
            '    MsgBox("ไม่พบข้อมูลซ้ำซ้อน", MsgBoxStyle.Information)
            '    Exit Sub
            'End If
            'For i = 1 To DT_m_person_Dup.Rows.Count - 1
            '    CID_Criteria = CID_Criteria & "'" & DT_m_person_Dup.Rows(i).Item("CID").ToString & "',"
            'Next


            'If CID_Criteria <> Nothing Then
            '    CID_Criteria = Mid(CID_Criteria, 1, Len(CID_Criteria) - 1) & ")"

            'End If
            If DlgDateRange.ShowDialog = Windows.Forms.DialogResult.Cancel Then Exit Sub




            Strsql = "select v.vn,v.hn,p.cid,p.pname,p.fname,p.lname,pr.person_id,pr.cid as prcid,pr.patient_hn,patient_link,if(p.fname=pr.fname,'Y','N') AS fname_match,if(p.lname=pr.lname,'Y','N') AS lname_match,if(p.hn=pr.patient_hn,'Y','N') as hn_match,if(p.cid=pr.cid,'Y','N') as cid_match,if(p.hn=pr.patient_hn,'Y','N') AS Link_match,if(p.sex=pr.sex,'Y','N') AS sex_match,p.sex,pr.sex,pr.pname, pr.fname, pr.lname from vn_stat  v"
            Strsql = Strsql & " left join patient p on v.hn = p.hn left join person pr on p.cid = pr.cid where  vstdate between '" & Pn_Framework.MysqlDateTimeFormat(DlgDateRange.DTP_F, False) & "'  and '" & Pn_Framework.MysqlDateTimeFormat(DlgDateRange.DTP_T, False) & "'  and (p.hn<>pr.patient_hn or p.hn<>pr.patient_hn)  and v.hn not like '99999%' group by vn order by hn "


            Dim DS_Documents As New DataSet
            DS_Documents = _mysql.GetMYSQLDataset(Strsql, "IDM", "reporttemplate", True)
            Dim TotalRow As Integer = DS_Documents.Tables(0).Rows.Count
            Dim AddRow As Integer


            Dim report1 As New FastReport.Report

            report1.Preview = PreviewControl2
            report1.Load(Application.StartupPath & "/Reports/rptChkRefService.frx")


            report1.AutoFillDataSet = True

            report1.RegisterData(DS_Documents)

            report1.GetDataSource("reporttemplate").Enabled = True

            report1.Refresh()
            report1.Preview = PreviewControl2
            report1.Show()


        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

 
End Class